package com.android.fastride.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;

import com.android.fastride.R;
import com.android.fastride.activity.base.BaseActivity;
import com.android.fastride.view.fragment.HelpFragment;
import com.android.fastride.view.widget.TopBar;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

public class HelpActivity extends BaseActivity {
    private static final String TAG = "HelpActivity";
    Unbinder unbinder;
    @BindView(R.id.tb_top_bar)
    TopBar tbTopBar;
    @BindView(R.id.tablayout)
    TabLayout tablayout;
    @BindView(R.id.tab_viewpager)
    ViewPager tabViewpager;

    public static void start(Context context) {
        Intent intent = new Intent(context, HelpActivity.class);
        context.startActivity(intent);
    }

    private Fragment[] mFragmentArrays = new Fragment[2];
    private String[] mTabTitles = new String[]{"常见问题","规则说明"};

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_help);
        unbinder = ButterKnife.bind(this);
        initView();
    }


    private void initView() {
        tbTopBar.setOnLeftAndRightClickListener(new TopBar.OnLeftAndRightClickListener() {
            @Override
            public void OnLeftButtonClick() {
                HelpActivity.this.finish();
            }
            @Override
            public void OnRightButtonClick() {

            }
        });

        tabViewpager.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager()) {
            @Override
            public Fragment getItem(int position) {
                    return HelpFragment.newInstance(position%2);
            }

            @Override
            public int getCount() {
                return 2;
            }

            @Override
            public CharSequence getPageTitle(int position) {
                return mTabTitles[position%2];

            }
        });
        tablayout.setupWithViewPager(tabViewpager);
    }


    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (unbinder != null) {
            unbinder.unbind();
            unbinder = null;
        }
    }
}
